#include <iostream>
#include "message.h"
#include "message1.h"
#include "message2.h"
#include "gtest/gtest.h"

using namespace std;

#ifdef ___win32_
//在cmakelist中引用了，此处路径不通用
//#pragma comment(lib, "../mypro2buf/gtest/lib/gtest.lib")
#endif

void testMessage1()
{
    LoginData data;

    data.username = "gt";
    data.password = "123";

    MessageLoginRequest loginRequest(data);

    uint32_t  msgSize = 0;
    uint8_t*  msgBuf  = nullptr;

    loginRequest.serialize(msgSize, &msgBuf);

    MessageLoginRequest loginRequest2;

    loginRequest2.deserialize(msgSize, msgBuf);

    EXPECT_EQ(data.username,  loginRequest2.getLogin().username);
    EXPECT_EQ(data.password,  loginRequest2.getLogin().password);

    if (msgBuf)
    {
        delete [] msgBuf;
        msgBuf = nullptr;
    }
}

void testMessage2()
{
    InfoData data;

    data.height  = 180;
    data.weight  = 150;
    data.age     = 30;
    data.married = true;

    MessageInfoResponse infoResponse(data);

    uint32_t  msgSize = 0;
    uint8_t*  msgBuf  = nullptr;

    infoResponse.serialize(msgSize, &msgBuf);

    MessageInfoResponse infoResponse2;

    infoResponse2.deserialize(msgSize, msgBuf);

    EXPECT_EQ(data.height,  infoResponse2.getInfo().height);
    EXPECT_EQ(data.weight,  infoResponse2.getInfo().weight);
    EXPECT_EQ(data.age,     infoResponse2.getInfo().age);
    EXPECT_EQ(data.married, infoResponse2.getInfo().married);

    if (msgBuf)
    {
        delete [] msgBuf;
        msgBuf = nullptr;
    }
}

TEST(MessageTest, message1)
{
    testMessage1();
}
TEST(MessageTest, message2)
{
    testMessage2();
}

int main()
{
    ::testing::InitGoogleTest();
    return RUN_ALL_TESTS();
}
